<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 意见反馈
 */
class Feedback extends Api
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 新增反馈
     * @ApiMethod   (POST)
     * @param string $channel_code 渠道号
     * @param string $deviceid 设备id
     * @param string $content 反馈内容
     * @param string $contact_info 联系方式
     * @param string $sign sign
     */
    public function add()
    {
        $insert['channel_code'] = $this->request->request('channel_code');
        $insert['deviceid']     = $this->request->request('deviceid');
        $insert['content']      = $this->request->request('content');
        $insert['contact_info'] = $this->request->request('contact_info');
        $insert['ip'] = request()->ip();
        $insert['createtime'] = time();
        
        $where = [];
        if (!empty($insert['deviceid'])) {
            $where['deviceid'] = $insert['deviceid'];
        }

        if (0 < Db::name('feedback')->where($where)->where('createtime', '>', (time() - 300))->count() || 10 < Db::name('feedback')->where($where)->where('createtime', '>', time() - 86400)->count()) {

        } else {
            Db::name('feedback')->insert($insert);
        }
        $this->success('success');
    }

}
